package src.first;

import java.lang.reflect.Field;
import java.lang.reflect.Method;

public class MoreFields {
    int i;
    public float f;
    protected boolean b;
    private String s;

    public int getI() {
        return i;
    }

    public void setI(int i) {
        this.i = i;
    }

    public float getF() {
        return f;
    }

    public void setF(float f) {
        this.f = f;
    }

    public boolean isB() {
        return b;
    }

    public void setB(boolean b) {
        this.b = b;
    }

    public String getS() {
        return s;
    }

    public void setS(String s) {
        this.s = s;
    }

    public static void main(String[] args) {
        try {
            MoreFields moreFields = new MoreFields();
            Class<?> aClass = moreFields.getClass();
            Field[] declaredFields = aClass.getDeclaredFields();
            for (Field declaredField : declaredFields) {
                System.out.println(declaredField.getName()+","+declaredField.getType()+","+declaredField.getModifiers());
                Class<?> type = declaredField.getType();
                if(type.equals(int.class)){
                    declaredField.setInt(moreFields,1);
                } else if (type.equals(float.class)) {
                    declaredField.setFloat(moreFields,5f);
                } else if (type.equals(boolean.class)) {
                    declaredField.setBoolean(moreFields,true);
                }else {
                    declaredField.set(moreFields,"dhshg");
                }
                System.out.println("修改后的值："+declaredField.get(moreFields));
            }


        } catch (IllegalAccessException e) {
            throw new RuntimeException(e);
        }

    }
}
